from sqlalchemy import *
from migrate import *
from datetime import datetime
from migrate.changeset import *

meta = MetaData(migrate_engine)

Diver = Table('Diver', meta,
  Column('id', Integer, primary_key=True,autoincrement=True),
  Column('firstname', Unicode(120)),
  Column('middlename', Unicode(120)),
  Column('lastname', Unicode(120)),
  Column('title', Unicode(120)),
  Column('sex', SmallInteger),
  Column('birthdate', DateTime),
  Column('passport', Unicode(120)),
  Column('address_id',Integer,ForeignKey('Address.id')),
  Column('contact_id',Integer,ForeignKey('Contact.id')),
  Column('user_id', Integer(),ForeignKey('tg_user.user_id')),
)
tg_user = Table('tg_user', meta,
  Column('user_id', Integer, autoincrement=True, primary_key=True),
  Column('user_name', Unicode(16), unique=True, nullable=False),
  Column('email_address', Unicode(255), unique=True, nullable=False),
  Column('display_name', Unicode(255)),
  Column('password', Unicode(80)),
  Column('created', DateTime, default=datetime.now),
  Column('diver_id', Integer(),ForeignKey('Diver.id'))
)


def upgrade():
    c = tg_user.c['diver_id']
    c.drop()
    
    
    
def downgrade():
    c = Column('diver_id', Integer(),ForeignKey('Diver.id'))
    tg_user.append_column(c)
    c.create(tg_user)
